﻿package view.popup
{
    import com.core.*;
    import com.sh.game.global.*;
    import flash.display.*;
    import flash.events.*;
    import flash.utils.*;
    import manager.*;
    import morn.core.components.*;
    import plugin.fashen.model.*;
    import pluginfw.nio.*;

    public class FaShenOpenView extends View implements IDialogUI
    {
        public var hpimg:Image;
        protected var uiXML:XML;
        private var curtime:Number;
        private var timer:Timer;
        private var background:Sprite;
        private var _exptimeID:uint = 0;

        public function FaShenOpenView()
        {
            this.uiXML = <View>r
n	t	t	t  <UrlImage url=""common_l/juexing.png"" x=""17"" y=""0""/>r
n	t	t	t  <Box x=""1"" y=""38"">r
n	t	t	t	t<Image url=""png.common.cs2_xudi"" x=""23"" y=""9"" width=""210"" sizeGrid=""1,1,1,1""/>r
n	t	t	t	t<Image url=""png.common.cs2_xu"" x=""23"" y=""9"" width=""10"" sizeGrid=""1,1,1,1"" var=""hpimg""/>r
n	t	t	t	t<Image url=""png.common.jingyan"" width=""255"" sizeGrid=""30,5,30,5""/>r
n	t	t	t  </Box>r
n	t	t	t</View>")("<View>
			  <UrlImage url="common_l/juexing.png" x="17" y="0"/>
			  <Box x="1" y="38">
				<Image url="png.common.cs2_xudi" x="23" y="9" width="210" sizeGrid="1,1,1,1"/>
				<Image url="png.common.cs2_xu" x="23" y="9" width="10" sizeGrid="1,1,1,1" var="hpimg"/>
				<Image url="png.common.jingyan" width="255" sizeGrid="30,5,30,5"/>
			  </Box>
			</View>;
            return;
        }// end function

        override protected function createChildren() : void
        {
            createView(this.uiXML);
            this.init();
            return;
        }// end function

        public function init() : void
        {
            this.background = new Sprite();
            this.background.graphics.beginFill(0, 0.5);
            this.background.graphics.drawRect(0, 0, GlobalLayer.instance.root.stage.stageWidth, GlobalLayer.instance.root.stage.stageHeight);
            this.background.graphics.endFill();
            this.background.addEventListener(MouseEvent.MOUSE_DOWN, this.onDown);
            PluginManager.instance.alertContainer.addChild(this.background);
            var _loc_1:Boolean = false;
            this.visible = false;
            this.background.visible = _loc_1;
            this.x = GlobalLayer.instance.root.stage.stageWidth - this.width >> 1;
            this.y = GlobalLayer.instance.root.stage.stageHeight - this.height >> 1;
            this.hpimg.width = 0;
            GlobalLayer.instance.root.addEventListener(Event.RESIZE, this.resizeHandler);
            return;
        }// end function

        public function show(param1:Object) : void
        {
            var _loc_2:* = ConfigDictionary.data.herolimit;
            var _loc_3:* = (_loc_2[1].limit as String).split("#");
            var _loc_4:* = ModelProxy.getValue("data", "user");
            if (ModelProxy.getValue("data", "user").level == int(_loc_3[1]))
            {
                var _loc_5:Boolean = true;
                this.visible = true;
                this.background.visible = _loc_5;
                this.curtime = 50;
                if (this.curtime > 0)
                {
                    if (this.timer == null)
                    {
                        this.timer = new Timer(50, 0);
                        this.timer.start();
                        this.timer.addEventListener(TimerEvent.TIMER, this.timerHandler);
                    }
                    else
                    {
                        this.timer.start();
                        this.timer.addEventListener(TimerEvent.TIMER, this.timerHandler);
                    }
                }
            }
            return;
        }// end function

        private function timerHandler(event:TimerEvent) : void
        {
            ModelProxy.change("zone", "stopRun", null);
            var _loc_3:String = this;
            var _loc_4:* = this.curtime - 1;
            _loc_3.curtime = _loc_4;
            this.hpimg.width = this.hpimg.width + 5;
            var _loc_2:* = this.hpimg.width;
            if (_loc_2 > 210)
            {
                this.hpimg.width = 210;
            }
            if (this.curtime <= 0)
            {
                this.timer.stop();
                this.timer.removeEventListener(TimerEvent.TIMER, this.timerHandler);
                this.hpimg.width = 210;
                if (this._exptimeID > 0)
                {
                    clearTimeout(this._exptimeID);
                    this._exptimeID = 0;
                }
                this._exptimeID = setTimeout(this.close, 10);
            }
            return;
        }// end function

        public function close() : void
        {
            if (this._exptimeID > 0)
            {
                clearTimeout(this._exptimeID);
                this._exptimeID = 0;
            }
            var _loc_3:Boolean = false;
            this.visible = false;
            this.background.visible = _loc_3;
            ModelProxy.change("mainui", "showFashen", null);
            this.hpimg.width = 0;
            var _loc_1:* = ConfigDictionary.data.hero;
            var _loc_2:* = new Output();
            _loc_2.writeVarInt(90001, false);
            _loc_2.writeByte(1);
            PluginManager.instance.sendToBufferServer("fashen", CMDFaShen.ZhaoHuan, _loc_2);
            ModelProxy.change("zone", "startRun", null);
            return;
        }// end function

        private function onDown(event:MouseEvent) : void
        {
            event.stopImmediatePropagation();
            return;
        }// end function

        private function resizeHandler(event:Event) : void
        {
            this.background.width = GlobalLayer.instance.root.stage.stageWidth;
            this.background.height = GlobalLayer.instance.root.stage.stageHeight;
            this.x = GlobalLayer.instance.root.stage.stageWidth - this.width >> 1;
            this.y = GlobalLayer.instance.root.stage.stageHeight - this.height >> 1;
            return;
        }// end function

    }
}
